package com.notice.quickaction;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

/**
 * 实现activity
 */
public class MyQuick extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        // 得到一个actionItem对象
        final ActionItem chart = new ActionItem();

        // 设置标题，图标，点击事件
        chart.setTitle("Chart");
        chart.setIcon(getResources().getDrawable(R.drawable.chart));
        chart.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Toast.makeText(MyQuick.this, "Chart selected", Toast.LENGTH_SHORT).show();
            }
        });

        final ActionItem production = new ActionItem();

        production.setTitle("Products");
        production.setIcon(getResources().getDrawable(R.drawable.production));
        production.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Toast.makeText(MyQuick.this, "Products selected", Toast.LENGTH_SHORT).show();
            }
        });

        Button btn1 = (Button) this.findViewById(R.id.btn1);
        // 点击按钮弹出
        btn1.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // 初始化一个QuickActions
                QuickActions qa = new QuickActions(v);
                // 为他添加actionitem
                qa.addActionItem(chart);
                qa.addActionItem(production);
                qa.addActionItem(production);
                qa.addActionItem(production);
                // 设置动画风格
                qa.setAnimStyle(QuickActions.ANIM_AUTO);

                qa.show();
            }
        });

        final ActionItem dashboard = new ActionItem();

        dashboard.setIcon(getResources().getDrawable(R.drawable.dashboard));
        dashboard.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Toast.makeText(MyQuick.this, "dashboard selected", Toast.LENGTH_SHORT).show();
            }
        });

        final ActionItem users = new ActionItem();

        users.setIcon(getResources().getDrawable(R.drawable.users));
        users.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Toast.makeText(MyQuick.this, "Products selected", Toast.LENGTH_SHORT).show();
            }
        });

        Button btn2 = (Button) this.findViewById(R.id.btn2);
        btn2.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                QuickActions qa = new QuickActions(v);

                qa.addActionItem(dashboard);
                qa.addActionItem(users);
                qa.setAnimStyle(QuickActions.ANIM_GROW_FROM_CENTER);

                qa.show();
            }
        });
    }
}
